﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;
using Verse.Sound;

namespace Miao.Stand
{
    public class FirstBombAbility : StandAbility
    {
        Command_StandRadiusTarget bomb_Target;
        Command_Action bomb_Action;
        public FirstBombAbility(StandPawn standPawn): base(standPawn)
        {
        
        }

        public override void Init()
        {
            base.Init();
            bomb_Target = new Command_StandRadiusTarget(this);
            this.SetDefField(bomb_Target);
            bomb_Target.order = 20;
            bomb_Target.targetingParams = new TargetingParameters()
            {
                //canTargetLocations = true,
                canTargetItems = true,
                canTargetPawns = true,
                canTargetBuildings = true,
                canTargetAnimals = true,
                canTargetHumans = true,
                canTargetPlants = true,
                mustBeSelectable = true,
                mapObjectTargetsMustBeAutoAttackable = false,
                thingCategory = ThingCategory.Item,//重要的目标选择范围
            };
            bomb_Target.action = (target) =>
            {
                StartCast();
                Job job = JobMaker.MakeJob(StandJobDefOf.StandSetupBomb, target);

                job.ignoreForbidden = true;

                stand.jobs.TryTakeOrderedJob(job, JobTag.Misc);
            };

            bomb_Action = new Command_Action();
            bomb_Action.defaultLabel = def.label + "(引爆)".Translate();
            bomb_Action.defaultDesc = "引爆被碰到的东西".Translate();
            bomb_Action.icon = Stand.ModSingleton.LoadIcon(def.label + "(引爆)"); ;
            bomb_Action.order = 20.1f;
            bomb_Action.action = () =>
            {
                StandSoundDefOf.KillerQueenClick.PlayOneShotOnCamera();
                //为了最后的忽略Things设置，要写全参数，难顶。
                var bombTarget = (this.stand as KillerQueenStand).bombTarget;
                GenExplosion.DoExplosion(bombTarget.PositionHeld, bombTarget.Map, (this.stand as KillerQueenStand).killQueenExplosionRadius, DamageDefOf.Bomb, stand.owner, -1, -1, null, null, null, bombTarget, null, 0, 1, false, null, 0, 1, 0, false, null, new List<Thing> { stand, stand.owner });
                (this.stand as KillerQueenStand).bombTarget = null;
            };
        }

        public override Gizmo DrawGizmo()
        {
          
            if ((this.stand as KillerQueenStand).bombTarget == null)
            {

                bomb_Target.disabled = !(PowerCostEnough(bomb_Target) & CooldownComplete(bomb_Target));
                return bomb_Target;
            }
            else
            {
                return bomb_Action;
            }
        }
    }
}
